{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6bc3eea1f68624ae",
   "metadata": {},
   "source": [
    "# Unspliced fraction from 10X bam files"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0bcb38c8bbbdea0",
   "metadata": {},
   "source": [
    "This notebook shows how  to calculate the unspliced fraction from 10X bam files using our built-in function.\n",
    "\n",
    "First, we load the necessary libraries and define the path to the input files."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ce363930b578f000",
   "metadata": {},
   "outputs": [],
   "source": [
    "import qclus as qc\n",
    "\n",
    "bam_path = \"/path/to/.bam\"\n",
    "bam_index_path = \"/path/to/.bam.bai\"\n",
    "barcodes_path = \"/path/to/barcodes.tsv.gz\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e8f585faa786798",
   "metadata": {},
   "source": [
    "Now we can calculate the unspliced fraction using the `fraction_unspliced_from_bam` function. This function calculates the fraction of unspliced molecules in each nucleus by counting the number of spliced and unspliced molecules in each nucleus. The function takes the following arguments:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf3cebc7",
   "metadata": {},
   "outputs": [],
   "source": [
    "fraction_unspliced = qc.utils.fraction_unspliced_from_bam(bam_path=bam_path,\n",
    "                                                bam_index_path=bam_index_path,\n",
    "                                                barcodes_path=barcodes_path, \n",
    "                                                tiles=80,  \n",
    "                                                cores=8)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bddca650d570de62",
   "metadata": {},
   "source": [
    "Now we can save the unspliced fraction to a csv file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0eb21cde",
   "metadata": {},
   "outputs": [],
   "source": [
    "fraction_unspliced.to_csv(\"fraction_unspliced.csv\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.1.-1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
